package com.gmp.thewizard;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class Panel extends View {

	private Avatar avatar;
	private static final String TAG = "Panel";
	
	public Panel(Context context){
		super(context);
		avatar = new Avatar(50, 50, 25);
	    setFocusable(true);
	}
	
	protected void onDraw(Canvas canvas){
		super.onDraw(canvas);
		canvas.drawColor(Color.WHITE);
		avatar.onDraw(canvas);
	}
	
	public boolean onTouchEvent(MotionEvent event){
		Log.v(TAG, "in onTouchEvent()");
		switch(event.getAction()){
		case MotionEvent.ACTION_DOWN:
			avatar.handleActionDown(event.getX(), event.getY());
			Log.v(TAG, "Coords: x=" + event.getX() + ", y=" + event.getY());
			break;
		case MotionEvent.ACTION_UP:
			if(avatar.isTouched())
				avatar.setTouched(false);
			break;
		case MotionEvent.ACTION_MOVE:
			if(avatar.isTouched())
				avatar.setPos(event.getX(), event.getY());
			invalidate(); // force callback onDraw()
			break;
		}
		return true;
	}
}
